<center>
  <span style="font-size:25px;"><%=@player.name%> [<%=@player.custom_name%>]</span>
<table width="100%" class="allboder">
<tr align="center">
  <td>
    <%if @pb.etc!=0%>
      Sales<br/>
      <%=number_with_delimiter(@pb.sold)%><br/><br/>
      ETC<br/>
      <%=number_with_delimiter(@pb.etc_revenue)%>
    <%else%>
      <br/>Sales<br/>
      <br/><%=number_with_delimiter(@pb.sold)%><br/><br/>
    <%end%>
  </td>
  <td>
    <%if @pb.etc!=0%>
      COGS<br/>
      <%=number_with_delimiter(@pb.cogs)%><br/><br/>
      ETC Cost<br/>
      <%=number_with_delimiter(@pb.etc_cost)%>
    <%else%>
      <br/>COGS<br/>
      <br/><%=number_with_delimiter(@pb.cogs)%><br/><br/>
    <%end%>
  </td>
  <td>
    <br/>Waste<br/>
    <br/><%=number_with_delimiter(@pb.waste_cogs)%><br/><br/>
  </td>
  <td>
    <%if @pb.promotion!=0%>
      Marketing<br/>
      <%=number_with_delimiter(@pb.marketing)%><br/><br/>
      Promotion<br/>
      <%=number_with_delimiter(@pb.promotion)%>
    <%else%>
    <br/>Marketing<br/>
    <br/><%=number_with_delimiter(@pb.marketing)%><br/><br/>
    <%end%>
  </td>
  <td>
    <br/>Futures P/L<br/>
    <br/><%=number_with_delimiter(@pb.futures_revenue)%><br/><br/>
  </td>
  <td>
    <br/>Depr.<br/>
    <br/><%=number_with_delimiter(@pb.depreciation)%><br/><br/>
  </td>
  <td>
    <br/>Interest<br/>
    <br/><%=number_with_delimiter(@pb.debt_interest+@pb.emergency_debt_interest)%><br/><br/>
  </td>
  <td>
    <br/>EBT<br/>
    <br/><%=number_with_delimiter(@pb.ebt)%><br/><br/>
  </td>
  <td>
    <br/>Tax<br/>
    <br/><%=number_with_delimiter(@pb.tax)%><br/><br/>
  </td>
  <td>
    <br/>Net Income<br/>
    <br/><%=number_with_delimiter(@pb.net_income)%><br/><br/>
  </td>
</tr>
<tr align="center">
  <td colspan="7">
    <div>
      <div style="float:left; width:65%">
        <table width="100%">
          <tr align="center">
            <td>
              A/R<br/>
              <%ar3 = Account.sum(:amount, :conditions=>["creditor_id=? AND due_year=? AND trade_year<=?", @player.id, @year+2, @year])%>
              <%ar2 = Account.sum(:amount, :conditions=>["creditor_id=? AND due_year=? AND trade_year<=?", @player.id, @year+1, @year])%>
              <%ar = Account.sum(:amount, :conditions=>["creditor_id=? AND due_year=? AND trade_year<=?", @player.id, @year, @year])%>
              <table width="100%" style="font-size:15px;">
                <tr align="center" valign="top">
                  <td>
                    ปี3<br/>
                    <%=number_with_delimiter(ar3)%><br/>
                    ?
                  </td>
                  <td>
                    ปี2<br/>
                    <%=number_with_delimiter(ar2)%><br/>
                    <%=number_with_delimiter(ar3)%>
                  </td>
                  <td>
                    ปี1<br/>
                    <%=number_with_delimiter(ar)%>=>0<br/>
                    <%=number_with_delimiter(ar2)%>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </div>
      <div style="float:right; width:35%">
        CASH<br/>
        <%=number_with_delimiter(@pb.cash)%><br/><br/>
        Futures<br/>
        <%=number_with_delimiter(@pb.futures)%>
      </div>
    </div>
  </td>
  <%
#    ar_value = Account.sum(:amount, :conditions=>["creditor_id=? AND due_year>? AND trade_year<=?", @player.id, @year, @year])
#    avarage_asset = 0
#    begin
#      avarage_asset = PlayerBalance.average(:total_assets, :conditions=>["player_id=? AND year<=? AND year>0", @player.id, @year])
#    rescue
#    end
  %>
  <td style="border :0px;">
    <br/>ROA =<br/>
    <br/><%begin%><%=number_with_precision(@pb.net_income.to_f/(@pb.total_assets), :precision=>4)%><%rescue%><%end%><br/><br/>
  </td>
  <td style="border :0px;">
    <br/>TURNOVER X<br/>
    <br/><%begin%><%=number_with_precision(@pb.sold.to_f/(@pb.total_assets), :precision=>4)%><%rescue%><%end%><br/><br/>
  </td>
  <td style="border :0px;">
    <br/>Profit Margin<br/>
    <br/><%begin%><%=number_with_precision(@pb.net_income.to_f/(@pb.sold), :precision=>4)%><%rescue%><%end%><br/><br/>
  </td>
</tr>
<tr align="center">
  <td colspan="2">
    <br/>RawMat. [Value | Unit]<br/>
    <br/><%=number_with_delimiter(@pb.rawmat_cost)%> | <%=number_with_delimiter(@pb.rawmat_unit)%><br/><br/>
  </td>
  <td colspan="2">
    <br/>Inventory [Value | Unit]<br/>
    <br/><%=number_with_delimiter(@pb.inventory_cost)%> | <%=number_with_delimiter(@pb.inventory_unit)%><br/><br/>
  </td>
  <td colspan="3" rowspan="3" valign="top">
    <span width="100%" style="text-align:left;">
    <table width="100%">
      <tr align="center">
        <td>
          A/P<br/>
          <%ap = Account.sum(:amount, :conditions=>["debtor_id=? AND due_year=? AND trade_year<=?", @player.id, @year, @year])%>
          <%ap2 = Account.sum(:amount, :conditions=>["debtor_id=? AND due_year=? AND trade_year<=?", @player.id, @year+1, @year])%>
          <%ap3 = Account.sum(:amount, :conditions=>["debtor_id=? AND due_year=? AND trade_year<=?", @player.id, @year+2, @year])%>
          <table width="100%" style="font-size:15px;">
            <tr align="center" valign="top">
              <td>
                ปี1<br/>
                0<=<%=number_with_delimiter(ap)%><br/>
                <%=number_with_delimiter(ap2)%>
              </td>
              <td>
                ปี2<br/>
                <%=number_with_delimiter(ap2)%><br/>
                <%=number_with_delimiter(ap3)%>
              </td>
              <td>
                ปี3<br/>
                <%=number_with_delimiter(ap3)%><br/>
                ?
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    </span>
    <br/>Debt<br/><br/>
    <br/>Emergency Debt<br/>
    <br/><%=number_with_delimiter(@pb.emergency_debt)%><br/><br/>
    <br/>Longterm Debt<br/>
    <br/>
      <table>
        <tr align="center">
          <td>Id</td>
          <td>Amount</td>
          <td>Rate</td>
          <td>ชำระคืนปลายปีที่</td>
        </tr>
        <%@debts.each do |d|%>
        <tr align="center">
          <td><%=d.code%></td>
          <td><%=number_with_delimiter(d.amount)%></td>
          <td><%=d.interest_rate * 100%> %</td>
          <td><%=d.end_year%></td>
        </tr>
        <%end%>
      </table>
    <br/><br/>
  </td>
  <td colspan="3" rowspan="3" valign="top">
    <br/>Equity<br/><br/><br/>
    <br/>Retained Earnings<br/>
    <br/><%=number_with_delimiter(@pb.retain_earning)%><br/><br/>
    <br/>Common Stock [Value | Unit]<br/>
    <br/><%=number_with_delimiter(@pb.common_stock)%> | <%=number_with_delimiter(@pb.common_stock_unit)%><br/><br/>
    <br/>Equity Per Share<br/>
    <br/><%=number_with_precision(@pb.equity_per_share, :precision=>2)%><br/><br/>
  </td>
</tr>
<tr align="center">
  <td colspan="4">
    <br/>Warehouses<br/>
    <br/>
    <table>
      <tr align="center">
        <td>Id</td>
        <td>Remain Value</td>
        <td>ใช้งานได้ถึงปลายปีที่</td>
      </tr>
      <%@warehouses.each do |w|%>
      <%

        ramian_year = @game_setting.warehouse_life - (@year - w.start_year + 1)
      %>
      <tr align="center">
        <td><%=w.code%></td>
        <td><%=number_with_delimiter(w.remain_value)%></td>
        <td><%=w.end_year%></td>
      </tr>
      <%end%>
    </table>
    <br/><br/>
  </td>
</tr>
<tr align="center">
  <td colspan="4">
    <br/>Factories<br/>
    <br/>
    <table>
      <tr align="center">
        <td>Id</td>
        <td>Remain Value</td>
        <td>ใช้งานได้ถึงปลายปีที่</td>
      </tr>
      <%@factories.each do |f|%>
      <%
        ramian_year = @game_setting.factory_life - (@year - f.start_year + 1)
      %>
      <tr align="center">
        <td><%=f.code%></td>
        <td><%=number_with_delimiter(f.remain_value)%></td>
        <td><%=f.end_year%></td>
      </tr>
      <%end%>
    </table>
    <br/><br/>
  </td>
</tr>
</table>
</center>